#ifndef RENDERAREA_H
#define RENDERAREA_H

#include "renderthread.h"
#include "complex.h"
#include <QTransform>
#include <QWidget>

class RenderArea : public QWidget
{
    Q_OBJECT

public:
    RenderArea(RenderThread *thread, QWidget *parent = 0);

    QSize minimumSizeHint() const;
    QSize sizeHint() const;
    Complex lambda() const;
    void setRenderThread(RenderThread *thread);

signals:
    void positionChanged(double x, double y);

public slots:
    void reset();
    void setIteration(int i);
    void setLambda(double x, double y);

protected:
    void paintEvent(QPaintEvent *event);
    void resizeEvent(QResizeEvent *event);
    void keyPressEvent(QKeyEvent *event);
    void wheelEvent(QWheelEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);

private slots:
    void updatePixmap(const QImage &image);

private:
    void render();
    void zoom(double zoomFactor);
    void scroll(int deltaX, int deltaY);

    RenderThread *renderThread;
    QPixmap pixmap;
    QTransform projectionMatrix;
    QTransform invertedMatrix;
    QTransform pixmapMatrix;
    Complex lambdaComplex;
    QPoint curPos;
    QPoint lastDragPos;
    int iteration;
    bool rendering;
};

#endif
